/*
*****************************************************************
inputs:
EZ_allm and US_allm

output: 
Table 1
*****************************************************************
*/

clear

if "$home" == "" {
    local wd = subinstr(c(pwd), "\", "/", .) 
	global home "`wd'"
	
}


*global DataStata "$home/DataforStata//Tables&Plots"
* Go one folder up
* Get parent directory manually
local lastslash = strrpos("$home", "/")   // Find last slash position
global home_parent = substr("$home", 1, `lastslash' - 1)   // Extract parent directory
global input "$home_parent/input"
global figures "$home_parent/Figures"

capture log close
log using "SumNQMP_replication.log", replace

use "$input/US_allm"
drop if year==.

d

* Four series:
* N: unadjusted
* Q: risk-neutral (adjusted for inflation)
* M: Adjusted for *M*aturity
* P: Adjusted for risk-neutral

* Nominal adjustment ***N PROBABILITIES
*****************************************************************
* HIGH INFLATION: Adjustment factor for the nominal adjustment:
gen adj_HI_NQ_10y=tail4_10y/Ntail4_10y
gen adj_HI_NQ_5y=tail4_5y/Ntail4_5y

* DEFLATION: Adjustment factor for the nominal adjustment:
gen adj_D_NQ_10y=tail0_10y/Ntail0_10y
gen adj_D_NQ_5y=tail0_5y/Ntail0_5y

* Maturity adjustment: 10Y PROBABILITIES
*****************************************************************
* HIGH INFLATION: Maturity adjustment
gen adj_HI_M=tail4_5y5y/tail4_10y

* DEFLATION: Maturity adjustment
gen adj_D_M=tail0_5y5y/tail0_10y

* Risk adjusment
*****************************************************************
* HIGH INFLATION: Risk adjustment
gen adj_HI_R=p4_5y5y_high_c/tail4_5y5y

* DEFLATION: Risk adjustment
gen adj_D_R=p0_5y5y_low_c/tail0_5y5y

* Table 1: US 
*****************************************************************
* Panel A: High inflation (9/21 - 8/23)
tabstat Ntail4_5y tail4_5y Ntail4_10y tail4_10y tail4_5y5y p4_5y5y_high_c if date_ym>=740&date_ym<=763, s(median n)

* full sample
tabstat Ntail4_5y tail4_5y Ntail4_10y tail4_10y tail4_5y5y p4_5y5y_high_c, s(p90 n)

* Panel B: Adjustments (9/21 - 8/23)
tabstat adj_HI_NQ_5y adj_HI_NQ_10y adj_HI_M adj_HI_R  if date_ym>=740&date_ym<=763, s(median n)

* full sample
tabstat adj_HI_NQ_5y adj_HI_NQ_10y adj_HI_M adj_HI_R, s(median n)

* Panel C: Deflation
tabstat Ntail0_5y tail0_5y Ntail0_10y tail0_10y tail0_5y5y p0_5y5y_low_c if year>=2011&year<=2012, s(median n)

* full sample
tabstat Ntail0_5y tail0_5y Ntail0_10y tail0_10y tail0_5y5y p0_5y5y_low_c, s(p90 n)

* Panel D: Adjustments (9/21 - 8/23)
tabstat adj_D_NQ_5y adj_D_NQ_10y adj_D_M adj_D_R  if year>=2011&year<=2012, s(median n)

* full sample
tabstat adj_D_NQ_5y adj_D_NQ_10y adj_D_M adj_D_R, s(median n)

* Table 1: EZ
*****************************************************************
clear all

use "$input/EZ_allm"
drop if year==.

* HIGH INFLATION: Adjustment factor for the nominal adjustment:
gen adj_HI_NQ_10y=tail4_10y/Ntail4_10y
gen adj_HI_NQ_5y=tail4_5y/Ntail4_5y

* DEFLATION: Adjustment factor for the nominal adjustment:
gen adj_D_NQ_10y=tail0_10y/Ntail0_10y
gen adj_D_NQ_5y=tail0_5y/Ntail0_5y

* maturity adjustment
gen adj_HI_M=tail4_5y5y/tail4_10y
gen adj_D_M=tail0_5y5y/tail0_10y

* HIGH INFLATION: Risk adjustment
gen adj_HI_R=p4_5y5y_high_c/tail4_5y5y

* DEFULATION: Risk adjustment
gen adj_D_R=p0_5y5y_low_c/tail0_5y5y

* Panels A and B: Inflation
tabstat Ntail4_5y tail4_5y Ntail4_10y tail4_10y tail4_5y5y p4_5y5y_high_c, s(p90 n)
tabstat adj_HI_NQ_5y adj_HI_NQ_10y adj_HI_M adj_HI_R, s(median n)

* Panels C and C: Deflation
tabstat Ntail0_5y tail0_5y Ntail0_10y tail0_10y tail0_5y5y p0_5y5y_low_c, s(p90 n)
tabstat adj_D_NQ_5y adj_D_NQ_10y adj_D_M adj_D_R, s(median n)

log off
log close

